package eng.agile;

import com.google.android.maps.MapActivity;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

@SuppressWarnings("unused")
public class TrakerActivity extends MapActivity {
	static String value1;
	static String value2;
	static EditText e1;
	static EditText e2;
	static TextView curText;

	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		final Builder builder = new AlertDialog.Builder(this);
		final Button route1 = (Button) findViewById(R.id.button2);

		route1.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				e1 = (EditText)findViewById(R.id.editText1);
				e2 = (EditText)findViewById(R.id.editText2);
				value1 = e1.getText().toString();
				value2 = e2.getText().toString();
				if( e2.getText().length()>0){
					if(e1.getText().length()==0)
						e1.setText("Current Address");
					builder.setMessage("Route From : "+e1.getText().toString()+"\nto : "+e2.getText().toString())
					.setCancelable(true)
					.setPositiveButton("yes", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int id) {
							//put calling function to get route from maps

							findViewById(R.id.progressBar1).setVisibility(1);
						}
					})
					.setNegativeButton("No", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int id) {
							dialog.cancel();
							findViewById(R.id.progressBar1).setVisibility(4);
						}
					});

					AlertDialog dialog = builder.create();
					dialog.show();
				}
				else{
					builder.setMessage("Try to enter Destination Value")
					.setNegativeButton("OK", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int id) {
							dialog.cancel();
							findViewById(R.id.progressBar1).setVisibility(4);
						}
					});
					AlertDialog dialog = builder.create();
					dialog.show();
				}
			}
		});

		final Button interChange = (Button) findViewById(R.id.button1);
		interChange.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				e1 = (EditText)findViewById(R.id.editText1);
				e2 = (EditText)findViewById(R.id.editText2);
				findViewById(R.id.progressBar1).setVisibility(4);
				if(e2.getText().length() > 0 ){
					
					if(e1.getText().length() == 0 )
						e1.setText("Current Location");
					
					value1 = e1.getText().toString();
					value2 = e2.getText().toString();
					
					e1.setText(value2);
					
					e2.setText(value1);
				}
				else
				{
					builder.setMessage("Try to Destination Value").setNegativeButton("OK", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int id) {
							dialog.cancel();
						}
					});
					AlertDialog dialog = builder.create();
					dialog.show();
				}
			}
		});


	}

	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}

}